﻿using Microsoft.Extensions.Logging;
using NewLife.Log;
using System;
using System.Collections.Generic;
using System.Text;

namespace TK.Socket
{
    /// <summary>
    /// 日志
    /// </summary>
    public class AppServerLog : Logger
    {
        private readonly ILogger<AppServer> _logger;

        /// <summary>
        /// ctor
        /// </summary>
        public AppServerLog(ILogger<AppServer> logger)
        {
            _logger = logger;
        }
        protected override void OnWrite(NewLife.Log.LogLevel level, string format, params object[] args)
        {
            var msg = format ?? string.Empty;
            if (args != null && args.Length >= 1)
            {
                msg = string.Format(msg, args);
            }

            switch (level)
            {
                case NewLife.Log.LogLevel.All:
                    _logger.LogTrace(msg, null);
                    break;
                case NewLife.Log.LogLevel.Debug:
                    _logger.LogDebug(msg, null);
                    break;
                case NewLife.Log.LogLevel.Info:
                    _logger.LogInformation(msg, null);
                    break;
                case NewLife.Log.LogLevel.Warn:
                    _logger.LogWarning(msg, null);
                    break;
                case NewLife.Log.LogLevel.Error:
                    _logger.LogError(msg, null);
                    break;
                case NewLife.Log.LogLevel.Fatal:
                    _logger.LogCritical(msg, null);
                    break;
                case NewLife.Log.LogLevel.Off:
                    break;
            }
        }
    }
}
